
    let submit = document.querySelector(".submit");
    let usernameid = document.querySelector("#username");
    let passwordid = document.querySelector("#password");
    let passwordid2 = document.querySelector("#password2");
    let cover = document.querySelector("#avatar-input")

    submit.onclick = function(){
        let username = usernameid.value;
        let pass1 = passwordid.value;
        let pass2 = passwordid2.value;
        
        //判断两次输入密码是否一致
        if(pass1 !== pass2){
            alert("两次密码输入不一致！")
            return
        }
        
        //获取到上传的头像图片内容 files[0]
        const avatar = cover.files[0]
        
        if(avatar != undefined){
            //提交：上传用户名 密码 头像
            const fd = new FormData()
            fd.append('username',username)
            fd.append('password',pass1)
            fd.append('avatar',avatar)

            //密码一致则提交注册信息
            $.ajax({
                url:'/api/user/register',
                method:'POST',
                data:fd,
                contentType: false,
                processData: false,
                success: resp =>{
                    if(resp.code === 200){
                        alert('注册成功！')
                    }else{
                        alert('注册失败！')
                    }
                    setTimeout(() => {
                        $('#shopReg').modal('hide')
                        usernameid.value = "";
                        passwordid.value = "";
                        passwordid2.value = "";
                    },20)
                }
            })
        }else{
            alert("请选择头像！")
        }
 
    }
